package com.xrf;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class UserLogin {
    private String userAccount;
    private String loginPassword;
    private Long register;
    private String retrieve;
    private Double rememberThePassword;
    private Long entry;
    private Long cancel;

    private static List<UserLogin> list = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public UserLogin() {}

    public UserLogin(String userAccount, String loginPassword, Long register, 
                    String retrieve, Double rememberThePassword, Long entry, Long cancel) {
        this.userAccount = userAccount;
        this.loginPassword = loginPassword;
        this.register = register;
        this.retrieve = retrieve;
        this.rememberThePassword = rememberThePassword;
        this.entry = entry;
        this.cancel = cancel;
    }

    // Getter and Setter methods
    public String getUserAccount() { return userAccount; }
    public void setUserAccount(String userAccount) { this.userAccount = userAccount; }
    public String getLoginPassword() { return loginPassword; }
    public void setLoginPassword(String loginPassword) { this.loginPassword = loginPassword; }
    public Long getRegister() { return register; }
    public void setRegister(Long register) { this.register = register; }
    public String getRetrieve() { return retrieve; }
    public void setRetrieve(String retrieve) { this.retrieve = retrieve; }
    public Double getRememberThePassword() { return rememberThePassword; }
    public void setRememberThePassword(Double rememberThePassword) { this.rememberThePassword = rememberThePassword; }
    public Long getEntry() { return entry; }
    public void setEntry(Long entry) { this.entry = entry; }
    public Long getCancel() { return cancel; }
    public void setCancel(Long cancel) { this.cancel = cancel; }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("用户账号:").append(userAccount).append("\t");
        builder.append("登录密码:").append(loginPassword).append("\t");
        builder.append("注册:").append(register).append("\t");
        builder.append("找回:").append(retrieve).append("\t");
        builder.append("记住密码:").append(rememberThePassword).append("\t");
        builder.append("登录:").append(entry).append("\t");
        builder.append("取消:").append(cancel).append("\t");
        return builder.toString();
    }

    // 数据操作方法
    public static void addData() {
        System.out.println("--------添加数据-------");
        System.out.println("请输入用户账号：");
        String userAccount = scanner.next();
        System.out.println("请输入登录密码：");
        String loginPassword = scanner.next();
        System.out.println("请输入注册：");
        Long register = scanner.nextLong();
        System.out.println("请输入找回：");
        String retrieve = scanner.next();
        System.out.println("请输入记住密码：");
        Double rememberThePassword = scanner.nextDouble();
        System.out.println("请输入登录：");
        Long entry = scanner.nextLong();
        System.out.println("请输入取消：");
        Long cancel = scanner.nextLong();
        
        UserLogin data = new UserLogin(userAccount, loginPassword, register, retrieve, 
                                     rememberThePassword, entry, cancel);
        list.add(data);
    }

    public static void removeData() {
        System.out.println("--------删除数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            list.remove(index);
            System.out.println("删除成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void updateData() {
        System.out.println("--------修改数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            System.out.println("请输入用户账号：");
            String userAccount = scanner.next();
            System.out.println("请输入登录密码：");
            String loginPassword = scanner.next();
            System.out.println("请输入注册：");
            Long register = scanner.nextLong();
            System.out.println("请输入找回：");
            String retrieve = scanner.next();
            System.out.println("请输入记住密码：");
            Double rememberThePassword = scanner.nextDouble();
            System.out.println("请输入登录：");
            Long entry = scanner.nextLong();
            System.out.println("请输入取消：");
            Long cancel = scanner.nextLong();
            
            UserLogin data = new UserLogin(userAccount, loginPassword, register, retrieve, 
                                         rememberThePassword, entry, cancel);
            list.set(index, data);
            System.out.println("修改成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void displayData() {
        System.out.println("--------数据显示-------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println("索引 " + i + ": " + list.get(i));
        }
    }
}